#!/bin/bash

dir=$1

if [ -z "$dir" ]; then
    echo "$0 <dir or file>"
    exit 1
fi

files=$(mktemp)

ls "$dir" > $files
readarray -t fs < "$files"

for i in $(seq 0 1 $((${#fs[@]} - 1)))
do
  f=${fs[$i]}
  echo "extracting audio from file: ${f} ..."
  af=$(echo "${f%% *}" | sed 's/播放//')
  ffmpeg -i "${dir}"/"${f}" -vn "${af}".mp3
done

rm -f $files
